package elitech.vietnam.weatherfashion.tabs.zoompager;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.URLUtil;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;

import elitech.vietnam.weatherfashion.R;
import elitech.vietnam.weatherfashion.config.Const;
import elitech.vietnam.weatherfashion.custom.ZoomImageView;
import elitech.vietnam.weatherfashion.custom.imageviewzoom.ImageViewTouchBase.DisplayType;
import elitech.vietnam.weatherfashion.dto.ProductDTO;
import elitech.vietnam.weatherfashion.tabs.AbstractFragment;

public class ZoomPagerItemFragment extends AbstractFragment {

	private ZoomImageView image;
	private ProductDTO product;
	private String link;
	
	public static ZoomPagerItemFragment init (ProductDTO link) {
		ZoomPagerItemFragment f = new ZoomPagerItemFragment();
		f.product = link;
		return f;
	}
	
	public static ZoomPagerItemFragment init (String link) {
		ZoomPagerItemFragment f = new ZoomPagerItemFragment();
		f.link = link;
		return f;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.layout_zoom_pager, container, false);
		setupView(view);
		
		image = (ZoomImageView) view.findViewById(R.id.zoom_image);
		image.setDisplayType(DisplayType.FIT_TO_SCREEN);
		if (product != null)
			UrlImageViewHelper.setUrlDrawable(image, Const.SERVER_IMAGE_URL + product.getImage(), R.drawable.loading_time);
		if (link != null && URLUtil.isValidUrl(link))
			UrlImageViewHelper.setUrlDrawable(image, link, R.drawable.loading_time);
		return view;
	}
	
}